home *** CD-ROM | disk | FTP | other *** search
/ Aminet 4 / Aminet 4 - November 1994.iso / aminet / dev / gcc / libnix.lha / gnu / lib / libnix / sources.lha / detach / cback20.S < prev    next >
Encoding:
Text File  |  1994-07-17  |  2.6 KB  |  160 lines

  1. | auto-detaching not baserelative startup code for gcc v2.3.3
  2. | (c) by M.Fleischer and G.Nikl Sat May 28 11:57 1994
  3. | No real bugs known but requires v37
  4.  
  5. | some specific defines
  6.  
  7. _LVOForbid    =    -132
  8. _LVOPermit    =    -138
  9. _LVOFindTask    =    -294
  10. _LVOGetMsg    =    -372
  11. _LVOReplyMsg    =    -378
  12. _LVOWaitPort    =    -384
  13. _LVOCloseLibrary =    -414
  14. _LVOOpenLibrary    =    -552
  15.  
  16. _LVOCreateNewProc =    -498
  17. _LVOCli        =    -492
  18.  
  19. pr_MsgPort    =      92
  20. pr_CLI        =     172
  21.  
  22. cli_Module    =      60
  23.  
  24. RETURN_OK    =       0
  25. RETURN_FAIL    =      20
  26.  
  27. | public symbols
  28.  
  29.         .globl    ___subexit
  30.         .globl    _geta4
  31.  
  32.         .text
  33.  
  34. | first entry - init some vars, check for cli or wb start
  35.  
  36. start:        movel    a0,d3
  37.  
  38.         movel    sp,_SaveSP
  39.         movel    4:W,a6
  40.         movel    a6,_SysBase
  41.  
  42.         subal    a1,a1
  43.         jsr    a6@(_LVOFindTask:W)
  44.         movel    d0,a3
  45.  
  46.         tstl    _DetachFlag
  47.         bnes    fromCLI
  48.  
  49.         tstl    a3@(pr_CLI:W)
  50.         bne    Detach
  51.  
  52. | wb start - get wbmsg
  53.  
  54. fromWB:        lea    a3@(pr_MsgPort:W),a0
  55.         jsr    a6@(_LVOWaitPort:W)
  56.         lea    a3@(pr_MsgPort:W),a0
  57.         jsr    a6@(_LVOGetMsg:W)
  58.         movel    d0,__WBenchMsg
  59.  
  60. | call __submain()
  61.  
  62. fromCLI:    movel    d3,___commandline
  63.         jmp    ___submain
  64.  
  65. | __subexit() entry - get return val, restore stackptr
  66.  
  67. ___subexit:    movel    __WBenchMsg,d2
  68.         beqs    todos
  69.         jsr    a6@(_LVOForbid:W)
  70.         movel    d2,a1
  71.         jsr    a6@(_LVOReplyMsg:W)
  72.  
  73. todos:        movel    sp@(4:W),d0
  74.         movel    _SaveSP,sp
  75.         
  76. | geta4() doesn´t do anything, but enables you to use
  77. | one source for both code models
  78.  
  79. _geta4:        rts
  80.  
  81. | detach the process from the shell task
  82.  
  83. NP_Seglist    =    0x800003e9
  84. NP_FreeSeglist    =    0x800003ea
  85. NP_StackSize    =    0x800003f3
  86. NP_Name        =    0x800003f4
  87. NP_Arguments    =    0x800003fd
  88.  
  89. Detach:        lea    ___dosname,a1
  90.         moveq    #37,d0
  91.         jsr    a6@(_LVOOpenLibrary:W)
  92.  
  93. | need a private DOSBase !!!
  94.  
  95.         movel    d0,d6
  96.         beq    nodos
  97.  
  98. | get pointer to CommandLineInterface (need not dereference BPTR)
  99.  
  100.         exg    d6,a6
  101.         jsr    a6@(_LVOCli:W)
  102.         movel    d0,a3
  103.         exg    d6,a6
  104.  
  105. | create process with disabled multitasking !!!
  106.  
  107.         jsr    a6@(_LVOForbid:W)
  108.  
  109. | save original stackpointer and setup required taglist
  110.  
  111.         movel    sp,a2
  112.         clrl    sp@-
  113.         movel    d3,sp@-
  114.         pea    NP_Arguments
  115.         movel    __procname,sp@-
  116.         pea    NP_Name
  117.         movel    __stack,d0
  118.         beqs    defstack
  119.         movel    d0,sp@-
  120.         pea    NP_StackSize
  121. defstack:    pea    1:W
  122.         pea    NP_FreeSeglist
  123.         movel    a3@(cli_Module:W),sp@-
  124.         pea    NP_Seglist
  125.         movel    sp,d1
  126.         exg    d6,a6
  127.         jsr    a6@(_LVOCreateNewProc:W)
  128.         exg    d6,a6
  129.         movel    a2,sp
  130.         movel    d0,_DetachFlag
  131.         beqs    noproc
  132.  
  133. | clear cli_Module to prevent unloading by the shell
  134.  
  135.         clrl    a3@(cli_Module:W)
  136.  
  137. | reenable multitasking - all done or maybe not ...
  138.  
  139. noproc:        jsr    a6@(_LVOPermit:W)
  140.  
  141. | close dos.library
  142.  
  143.         movel    d6,a1
  144.         jsr    a6@(_LVOCloseLibrary:W)
  145.  
  146. | exit graceful
  147.  
  148. nodos:        moveq    #RETURN_OK,d0
  149.         rts
  150.  
  151. | data area
  152.  
  153.         .data
  154.  
  155. .lcomm        _DetachFlag,4
  156. .comm        ___SaveSP,4
  157. .comm        _SysBase,4
  158. .comm        __WBenchMsg,4
  159. .comm        ___commandline,4
  160.